package com.skt.common_hr.congmoney.model
{
	import com.skt.common_hr.common.approval.IRequestApprovalProxy;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.congmoney.model.vo.CongMoneyWriteVO;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;

	public class CelebrationApprovalProxy extends CommonProxy implements IRequestApprovalProxy
	{
		public static const NAME:String = "CelebrationApprovalProxy";
		
		public var dataProvider:CongMoneyWriteVO;
		
		private var templateHTML:String = "";
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function CelebrationApprovalProxy(data:Object=null)
		{
			super(NAME, data);
			loadTemplate();
		}
 		
		private var _key:String = "";
		public function get key():String
		{
			return _key;
		}
		public function set key(k:String):void
		{
			_key = k;
		}
		

		public function get title():String 
		{
			var tmp:String = "경조사 신청";
			tmp += " (" + dataProvider.ZTEXT + ")"
			return tmp;
		}
		
		public function get content():String
		{
			return buildHTML(dataProvider);
		}
		
		public function get appCode():String 
		{
			return "06"; 	//
		}
 		

 		private function loadTemplate():void
		{
			var request:URLRequest = new URLRequest("assets/template/celebration_nos.tmp");
			loader.addEventListener(Event.COMPLETE, templateResult);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
		}
 			
		private function templateResult(event:Event):void
		{
			templateHTML = loader.data;
		}
		
		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace("ioErrorHandler: " + event);
		}

 		private function buildHTML(vo:CongMoneyWriteVO):String
		{
			var htmlAll:String = templateHTML;
			var htmlBlock:String = "";
			
			var ptnCname:RegExp  = /__CNAME__/; 
			var ptnIname:RegExp  = /__INAME__/;
			var ptnCodat:RegExp  = /__CODAT__/;
			var ptnCornm:RegExp  = /__CORNM__/;
			var ptnCoper:RegExp  = /__COPER__/;
			var ptnFtext:RegExp  = /__FTEXT__/;
			var ptnCosten:RegExp = /__COSTEN__/;
			
			//2013.5.2 j.t추가
			var ptnReper:RegExp = /__REPER__/;
			var ptnCnnct:RegExp = /__CNNCT__/;
			var ptnSndat:RegExp = /__SNDAT__/;
			var ptnPlace:RegExp = /__PLACE__/;
			
			var VISIBLE1:RegExp = /__VISIBLE1__/;
			
			
			
			htmlAll = htmlAll.replace(ptnCname, vo.CNAME);
			htmlAll = htmlAll.replace(ptnIname, vo.INAME);
			htmlAll = htmlAll.replace(ptnCodat, vo.CODAT_F);
			htmlAll = htmlAll.replace(ptnCornm, vo.ZTEXT);
			htmlAll = htmlAll.replace(ptnCoper, vo.COPER);
			htmlAll = htmlAll.replace(ptnFtext, vo.FTEXT);
			
			//2013.5.2 j.t추가
			htmlAll = htmlAll.replace(ptnReper, vo.REPER);
			htmlAll = htmlAll.replace(ptnCnnct, vo.CNNCT);
			htmlAll = htmlAll.replace(ptnSndat, vo.SNDAT);
			htmlAll = htmlAll.replace(ptnPlace, vo.PLACE);
			
			if(vo.COSEL == 'X') {
				htmlAll = htmlAll.replace(ptnCosten, vo.COSTEN);
			} else {
				htmlAll = htmlAll.replace(ptnCosten, '');
			}
			
			if(vo.ZWRTH == 'X' || vo.ZFNR == 'X'){
				htmlAll = htmlAll.replace(VISIBLE1, '');
			}else {
				htmlAll = htmlAll.replace(VISIBLE1, 'none');
			}
			return htmlAll;
		}
	}
}